<?php defined('InShopNC') or exit('Access Invalid!');?>

<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <div class="subject">
                <h3>系统通知</h3>
                <h5>系统通知管理</h5>
            </div>
        </div>
    </div>
    <!-- 操作说明 -->
    <div class="explanation" id="explanation">
        <div class="title" id="checkZoom"><i class="fa fa-lightbulb-o"></i>
            <h4 title="<?php echo $lang['nc_prompts_title'];?>"><?php echo $lang['nc_prompts'];?></h4>
            <span id="explanationZoom" title="<?php echo $lang['nc_prompts_span'];?>"></span> </div>
        <ul>
            <li>后台主动向会员发起消息（形式：站内信）</li>
        </ul>
    </div>
    <div class="left_box">
        <form id="form_item" action="<?php echo urlAdminSystem('system_inform', 'system_inform_send');?>" method="post">
            <p>
                <b>消息内容</b>
                <input type="text" name="message_body" value="" id="myeditor">
                <!-- <div id="myeditor"></div> -->
            </p>
            <div>
                <b>发送对象</b>
                <div class="emptybox" id="emptybox"></div>
            </div>
            
            <input type="hidden" name="member_ids" value="">
            <div id="item_members" class="mb_item_members"></div>
            <div class="bot"><a id="btn_save" class="ncap-btn-big ncap-btn-green" href="javascript:;">发送</a> </div>
        </form>
    </div>
    <div class="search-members right_box">
      <h3>选择会员添加</h3>
      <h5>会员关键字：</h5>
      <input id="txt_member_name" type="text" class="txt w200" name="">
      <a id="btn_mb_special_member_search" class="ncap-btn" href="javascript:;" style="vertical-align: top; margin-left: 5px;">搜索</a>
      <div id="mb_special_members_list"></div>
    </div>
</div>
<script id="item_goods_template" type="text/html">
    <div nctype="item_image" class="item">
        <input type="hidden" nctype="member_id" name="member_id" value="<%=member_id%>">
        <div class="member-name"><%=member_name%></div>
        <div class="member-pic"><img title="<%=member_name%>" src="<%=member_image%>" /></div>
        <a nctype="btn_del_item_image" href="javascript:;">删除</a>
    </div>
</script> 
<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/js/template.min.js" charset="utf-8"></script> 
<script src="<?php echo RESOURCE_SITE_URL;?>/js/jquery.ajaxContent.pack.js" type="text/javascript"></script> 
<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/kindeditor/kindeditor-min.js" charset="utf-8"></script>
<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/kindeditor/lang/zh_CN.js" charset="utf-8"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $('#btn_save').on('click', function() {
            qeditor.sync("#myeditor");
            var html = qeditor.html();
            $('#form_item').submit();
        });
        $('#btn_mb_special_member_search').on('click', function() {
            var url = '<?php echo urlAdminSystem('system_inform', 'member_list');?>';
            var keyword = $('#txt_member_name').val();
            if ((typeof keyword == 'undefined') || (keyword.length <= 0)) {
                showError('抱歉，筛选会员条件。');
                return false;
            }
            if(keyword) {
                $('#mb_special_members_list').load(url + '&' + $.param({keyword: keyword}));
            }
        });

        $('#mb_special_members_list').on('click', '[nctype="btn_add_member"]', function() {
            $("#emptybox").remove();
            var item = {};
            item.member_id = $(this).attr('data-member-id');
            item.member_name = $(this).attr('data-member-name');
            item.member_image = $(this).attr('data-member-image');
            //判断是否该会员是否已经存在
            var member_term = 'input[nctype="member_id"][value="' + item.member_id + '"]';
            var if_exist = $('#item_members').find(member_term).length;
            if (if_exist > 0){
                showError('抱歉，已经选择了该用户！');
                return false;
            }
            var html = template.render('item_goods_template', item);
            $('#item_members').append(html);

            updateMembersIds(); // 重新设置 member_ids

        });

        //删除图片
        $('#item_members').on('click', '[nctype="btn_del_item_image"]', function() {
            $(this).parents('[nctype="item_image"]').remove();
            updateMembersIds();
        });

        // 更新member_ids的值
        function updateMembersIds() {
            var member_ids = new Array();
            $('#item_members').find('input[name="member_id"]').each(function(){
                var member_id = $(this).val();
                member_ids.push(member_id);
            });
            $('input[name="member_ids"]').val(member_ids);
        }

        var qeditor = KindEditor.create('#myeditor', {
            items : ['link'],
            width : '100%'

        });

    });

</script> 

